library EngineerUpgrades initializer init requires LegacySystem


	private function Trig_Engineer_Upgrades_Conditions takes nothing returns boolean 
		if (GetLearnedSkillBJ() == 'A04T' ) then
			 return true
		elseif (GetLearnedSkillBJ() == 'A066' ) then
			 return true
		endif
		return false
	endfunction

	private function Trig_Engineer_Upgrades_Actions takes nothing returns nothing

		local player p = GetTriggerPlayer()
		if GetLearnedSkill()=='A04T' then
			call SetPlayerTechResearched( p, 'R002', GetPlayerTechCount(p,'R002',true)+1 )
		elseif GetLearnedSkill()=='A066' then //Nano Processor
			if GetPlayerTechCountSimple('R00S',p)==0 then
				call SetPlayerTechResearched(p,'R00S',1)
				call ALICEText(5.0, "|cffcd950cALICE|r : " + GetPlayerName(p) + " is now equipped with the MK-2 Nano Processor. Squad members can now draw energy from the Combat Engineer." )
			else
				call IncUnitAbilityLevel( udg_Hero[GetConvertedPlayerId(p)], 'A069' )
			endif
			call SetPlayerTechResearched( p, 'R00Q', GetPlayerTechCount(p,'R00Q',true)+1 )
		endif
		if udg_Mode!=3 and GetPlayerTechCount(p,'R002',true)==5 and GetPlayerTechCount(p,'R00Q',true)==5 then
			call DestroyTrigger(GetTriggeringTrigger())
		endif
		set p = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger(  )
		call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_HERO_SKILL )
		call TriggerAddCondition( t, Condition( function Trig_Engineer_Upgrades_Conditions ) )
		call TriggerAddAction( t, function Trig_Engineer_Upgrades_Actions )
	endfunction

endlibrary